|
|
|
|
|
|
|
Private Sub cmdPrev_Click()
adcBooks.Recordset.MovePrevious
End Sub
Private Sub cmdQuit_Click()
End
End Sub |
|
|
|
|
|
|
|
|
Now, run the application and try moving around the rows. You can see that the operation of the ADODC is almost identical to the original Data control. |
|
|
|
|
|
|
|
|
The ADODC also provides the record-navigation functions that users and the application need to access the data. With these buttons (refer to Figure 10.1), users can move to the first or last record in the recordset, or to the next or previous record in the recordset. The button design is similar to the buttons you would find on a VCR or CD player, making the buttons very easy to understand. |
|
|
|
|
|
|
|
|
The Data control also has a Caption property that you can use to display any important information, such as the last name of the address record you're browsing. You can't set the Caption property automatically; you do it by adding the following line of code to the ADODC's MoveComplete routine: |
|
|
|
|
|
|
|
|
dtaMyAddress.Caption = dtaMyAddress.Recordset.Fields(Title) |
|
|
|
|
|
|
|
|
This is actually using the capabilities of the ActiveX Data Objects, which allow you to access the database from within your application code. As you can see, the Data control has a lot of capabilities for you to use. |
|
|
|
|
|
|
|
|
Note To access the ActiveX Data Objects, add the reference in the Object Browser from the Visual Basic menu. |
|
|
|
|
|
|
|
|
|
When you invoke the Data control's Delete method, the current record is deleted from the database but is still held in the Data control's buffer until a Move method is executed. If you don't explicitly move to another record, an error will occur. |
|
|
|
|
|
|
|
|
Although Data controls are covered in every book written about Visual Basic, they're always shown as a single control on a form. To make use of the capabilities to quickly add database access, many complex applications that need access to different tables and queries will use multiple Data controls on the same form. Also, in many cases, the Data control itself isn't visible on the form when the application is executing. This means that even the four functions that it supplies must be added to the form by means of additional code. |
|
|
|
|
|